﻿using Device.API.Applcation.Command.UnitCommand;
using Device.Domain;
using Device.Infrstructre;
using Device.Infrstructre.Interface;
using MediatR;

namespace Device.API.Applcation.CommandHandlers.UnitCommandHandlers
{
    /// <summary>
    /// 新增单位中介者
    /// </summary>
    public class UnitCreateCommandHandlers : IRequestHandler<UnitCreateCommand, int>
    {
        private readonly IUnitRepository _unitRepository;
        public UnitCreateCommandHandlers(IUnitRepository unitRepository)
        {
            _unitRepository = unitRepository;
        }

        public async Task<int> Handle(UnitCreateCommand request, CancellationToken cancellationToken)
        {
            var unitModel = new UnitModel() { UnitName = request.UnitName, UnitCode = request.UnitCode, Uremark = request.Uremark, Office_Id = request.Office_Id, User_Id = request.User_Id, AddName = request.AddName, AddTime = request.AddTime };
            return await _unitRepository.AddAsync(unitModel);
        }
    }
}
